<template>
	<view>
		<view class="listbox" v-for="(item, index) in list" :key="index" @click="toDetail(item)">
			<view class="title">
				<view>{{ item.carNo }}</view>
				<view>¥{{ item.totalAmount }}</view>
			</view>
			<view class="title" v-if="item.outTime" style="height: 50rpx;border: none;font-size: 28rpx;margin-top: 30rpx;">
				<view>出场时间：</view>
				<view>{{ item.outTime }}</view>
			</view>

			<view class="infobox">
				<view class="info">
					<view class="leftbox">
						<image src="../../static/dw.png"></image>
						<view>{{ item.gateName }}</view>
					</view>
					<view>{{item.key=='9h298ctj'?'后广场停车场':item.key=='1kebvqjq'?'地面停车场':'地库停车场'}}</view>
				</view>
				<view class="info">
					<view class="leftbox">
						<image src="../../static/dw.png"></image>
						<view>停车时间</view>
					</view>
					<view>{{ item.outTime?getDuration(item.enterTime, item.outTime):'暂未出场' }}</view>
				</view>
			</view>
			
		</view>
		<kong v-if="list.length==0"></kong>
	</view>
</template>

<script>
	import kong from '../../components/kong.vue'
	export default {
		components: {
			kong
		},
		data() {
			return {
				page: 1,
				loading: false,
				isEnd: false,
				list: []
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			toDetail(item) {
				uni.navigateTo({
					url: '/pages/carinfo/carinfo?info=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			async getList() {
				if (this.loading || this.isEnd) return
				try {
					this.loading = true
					let {
						data
					} = await this.$http({
						url: '/api/Wechat/parkCarList',
						method: 'get',
						data: {
							page_index: this.page,
							page_size: 10,
						}
					})
					this.list = [...this.list, ...data]
					this.isEnd = data.length < 10
					this.page++
				} catch (err) {

				} finally {
					this.loading = false
				}
			},
			getDuration(stime, etime) {
				let seconds = Math.abs((Date.parse(etime) - Date.parse(stime)) / 1000)
				let hour = Math.floor(seconds / 3600)
				let minute = Math.floor((seconds % 3600) / 60)
				let second = Math.floor((seconds % 3600) % 60)
				return `${hour < 10 ? '0' + hour : hour}h ${minute < 10 ? '0' + minute : minute}m ${second < 10 ? '0' + second : second}s`
				// if(hour==0){
				// 	return `${minute < 10 ? '0' + minute : minute}m ${second < 10 ? '0' + second : second}s`
				// }else if(hour==0&&minute==0){
				// 	return `${second < 10 ? '0' + second : second}s`
				// }else{
				// 	return `${hour < 10 ? '0' + hour : hour}h ${minute < 10 ? '0' + minute : minute}m ${second < 10 ? '0' + second : second}s`
				// }
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.listbox {
		width: 690rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 0 auto 24rpx auto;
		padding-bottom: 40rpx;

		.title {
			padding: 0 20rpx;
			width: 650rpx;
			display: flex;
			justify-content: space-between;
			height: 116rpx;
			align-items: center;
			border-bottom: solid 2rpx #F1F1F1;
		}

		.infobox {
			width: 690rpx;
			display: flex;
			align-items: center;

			.info {
				width: 325rpx;
				padding-left: 20rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;

				.leftbox {
					display: flex;
					align-items: center;
					margin: 40rpx 0 26rpx 0;
					color: #555555;

					image {
						width: 20rpx;
						height: 26rpx;
						margin-right: 10rpx;
					}
				}
			}

		}
	}
</style>